package com.jianying.mapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.jianying.base.BaseMapper;
import com.jianying.dataSource.TargetDataSource;
import com.jianying.domain.Category;


@Repository("categoryMapper")
public class CategoryMapper extends BaseMapper {

	private static final String NAME_SPACE = "com.jianying.mapper.CategoryMapper.";
	
	@TargetDataSource(name="ds1")
	public void insertBatch(List<Category> categories) {
		getSqlSessionTemplate().insert(namespace() + "insertBatch", categories);
	}
	
	public List<Category> all(Integer tenantId) {
		return getSqlSessionTemplate().selectList(namespace() + "all", tenantId);
	} 
	
	public Category find(Integer id) {
		return getSqlSessionTemplate().selectOne(namespace() + "find", id);
	} 
	
	@TargetDataSource(name="ds1")
	public Category byName(Integer tenantId, String name) {
		Map<String, Object> map = new HashMap<>();
		map.put("tenantId", tenantId);
		map.put("name", name);
		return getSqlSessionTemplate().selectOne(namespace() + "byName", map);
	} 
	
	private String namespace(){
		return NAME_SPACE;
	}
}
